package com.auto.learning.activity;

import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.R.integer;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import cn.jpush.android.api.JPushInterface;

import com.auto.learning.MainActivity;
import com.auto.learning.R;
import com.auto.learning.adapter.LichengBooklistAdapter;
import com.auto.learning.adapter.PaihangAdapter;
import com.auto.learning.bean.BannerItem;
import com.auto.learning.bean.Banner_H5;
import com.auto.learning.bean.BookBean;
import com.auto.learning.bean.BookListModel;
import com.auto.learning.bean.BreakPointBean;
import com.auto.learning.bean.BreakPointTable;
import com.auto.learning.bean.CacheTypeBean;
import com.auto.learning.bean.PaihangBean;
import com.auto.learning.bean.ReadLichengBean;
import com.auto.learning.bean.ResponeResult;
import com.auto.learning.bean.SelectionVo;
import com.auto.learning.bean.UserBaseInfo;
import com.auto.learning.bean.UserInfoBean;
import com.auto.learning.bean.VideoBean;
import com.auto.learning.event.Handle;
import com.auto.learning.event.listener.DialogListener;
import com.auto.learning.net.Cache;
import com.auto.learning.net.DownLoadInfo;
import com.auto.learning.net.HttpCommonInfo;
import com.auto.learning.net.HttpRequestHelper;
import com.auto.learning.service.MyUserInfo;
import com.auto.learning.service.PlayService;
import com.auto.learning.sharesdk.tools.ShareOpUtils;
import com.auto.learning.store.core.StaticReference;
import com.auto.learning.store.core.table.UserInfoTable;
import com.auto.learning.tools.CommonMethod;
import com.auto.learning.tools.FileUtil;
import com.auto.learning.tools.TemporaryVariable;
import com.auto.learning.view.CommonAlertDialog;
import com.auto.learning.view.RoundImageView;
import com.auto.learning.view.ShareView;
import com.auto.learning.view.SharedPreferencesUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.dao.RawRowMapper;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sdu.didi.openapi.DiDiWebActivity;

public class SplashActivity extends Activity implements Callback {
	
	private static final int SPLASH_GET_USERID_FAIL = 2;
	private ArrayList<BannerItem> bannerList = new ArrayList<BannerItem>();
	private ArrayList<BookBean> bookList = new ArrayList<BookBean>();
	private ArrayList<BookBean> newList = new ArrayList<BookBean>();  //每周新书
	private ArrayList<BookBean> topList = new ArrayList<BookBean>();  //周（月）排行版
	
	
	public final static int GETUSERINFO_SUCCESS = 1; 
	public final static int GETMYREADBOOK_SUCCESS = 2; 
	private ArrayList<BookBean> list = new ArrayList<BookBean>();
	
	private TextView tv_other,tv_china,tv_usa,tv_eur,tv_username,tv_grade,tv_has_read,tv_jinji;
	private ImageView fg_me_userpic,image_to_read,image_share,image_backgroup,image_up,image_phb_top,imageView1;
	private RoundImageView image_face;
	
	private ListView listview_paim;
	private PaihangAdapter adapter;
	private LichengBooklistAdapter lichengBooklistAdapter;
	private GridView gv_booklist;
	ArrayList<PaihangBean> pList = new ArrayList<PaihangBean>();
	private PullToRefreshScrollView scrollView2;
	
	private Handle handle = new Handle(this){
		public void handleMessage(android.os.Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case HttpRequestHelper.GETDATA_SUCCESS:
				ResponeResult responeResult = (ResponeResult) msg.obj;
				if (responeResult != null) {
					ArrayList<PaihangBean> m_list = new Gson().fromJson(responeResult.getData(), new TypeToken<ArrayList<PaihangBean>>(){}.getType());
					if (pList != null) {
						pList.clear();
						pList.addAll(m_list);
						if (adapter != null) {
							adapter.notifyDataSetChanged();
						}
						CommonMethod.setListViewHeight(listview_paim);
					}
				}
				break;
			case GETMYREADBOOK_SUCCESS:
				ResponeResult read_responeResult = (ResponeResult) msg.obj;
				if (read_responeResult != null) {
					ArrayList<BookBean> r_list = new Gson().fromJson(read_responeResult.getData(), new TypeToken<ArrayList<BookBean>>(){}.getType());
					if (list != null) {
						list.clear();
						list.addAll(r_list);
						if (lichengBooklistAdapter != null) {
							lichengBooklistAdapter.notifyDataSetChanged();
						}
						CommonMethod.setGridViewHeight(gv_booklist, 3, CommonMethod.dip2px(SplashActivity.this, 8));
					}
				}
				break;
			case GETUSERINFO_SUCCESS:
				ResponeResult readlicheng_Result = (ResponeResult) msg.obj;
				if (readlicheng_Result != null) {
					ReadLichengBean lichengBean = new Gson().fromJson(readlicheng_Result.getData(), new TypeToken<ReadLichengBean>(){}.getType());
					showData(lichengBean);
				}
				break;
			case 11:
			case 12:
				ResponeResult m_result = (ResponeResult) msg.obj;
				try {
					if (m_result != null) {
						JSONObject jsonObject = new JSONObject(m_result.getData());
						int isChange = jsonObject.getInt(HttpRequestHelper.BOOKNUM_ISCHANGED);  //1否2是
						int bookNum = jsonObject.getInt("bookNum");
						int userId = (int) SharedPreferencesUtils.getParam(SplashActivity.this, HttpRequestHelper.USERID, 0);
						if (isChange == 2) {
							SharedPreferencesUtils.setParam(SplashActivity.this,  userId + "_" + HttpRequestHelper.BOOKNUM_ISCHANGED, isChange);
							//EventBus.getEventBus("readbook_num_change").post(new BookNumChangeEvent(bookNum));
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				break;
			
			}
		};
	};
	
	private Handler handler = new Handle(this){
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case SPLASH_GET_USERID_FAIL:
				CommonAlertDialog alertDialog = new CommonAlertDialog(SplashActivity.this);
				alertDialog.setTextMessage("亲，网络有些不给力，请稍后重试");
				alertDialog.setShowTitle(true);
				String[] a = {"重试","取消"};
				alertDialog.setBtns(new DialogListener() {

					@Override
					public void okButtonClick(Dialog dialog) {
						dialog.dismiss();
						initData(false);
					}

					@Override
					public void cancelButtonClick(Dialog dialog) {
						dialog.dismiss();
						finish();
						System.exit(0);
					}

					@Override
					public void otherButtonClick(Dialog dialog) {
						dialog.dismiss();
					}}, a);
				alertDialog.show();
				break;
			case 4:
				checkOver();
				break;
			}
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
//		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		DiDiWebActivity.registerApp(HttpRequestHelper.DIDI_APPID, HttpRequestHelper.DIDI_SCERET);
		//boolean flag = false;
		boolean isShowPaihan = false;
		int userId = (int) SharedPreferencesUtils.getParam(this, HttpRequestHelper.USERID, 0);
		int isChange = (int)SharedPreferencesUtils.getParam(this, userId+"_"+HttpRequestHelper.BOOKNUM_ISCHANGED, 1);
		/*String beforeTime = (String) SharedPreferencesUtils.getParam(this, "beforeShowTime", "");
		if (!TextUtils.isEmpty(beforeTime) && !beforeTime.equals(DateUtil.getCurrDate())) {
			flag = true;
		}*/
		initIntent();
		if (isChange == 2 && userId != 0 && TextUtils.isEmpty(JPush_Data)) {
			isShowPaihan = true;
			setContentView(R.layout.activity_licheng);
			//SharedPreferencesUtils.setParam(this, "beforeShowTime", DateUtil.getCurrDate());
			SharedPreferencesUtils.setParam(this, userId+"_"+HttpRequestHelper.BOOKNUM_ISCHANGED, 1);
			initImageLoader();
			initView();
		} else {
			isShowPaihan = false;
			setContentView(R.layout.splash_activity);
			ImageView image_splash = (ImageView) findViewById(R.id.image_splash);
			boolean isNeedShowScreenBoot = (boolean) SharedPreferencesUtils.getParam(SplashActivity.this, "isNeedShowScreenBoot", false);
			String screenImageUrl = (String) SharedPreferencesUtils.getParam(SplashActivity.this, "ScreenBootImageUrl", "");
			if (isNeedShowScreenBoot && !TextUtils.isEmpty(screenImageUrl)) {
				ImageLoader.getInstance().displayImage(screenImageUrl, image_splash);
				
			}else {
				image_splash.setImageBitmap(CommonMethod.readBitMap(this, R.drawable.splash));
				/*if (TextUtils.isEmpty(beforeTime)) {
					SharedPreferencesUtils.setParam(this, "beforeShowTime", DateUtil.getCurrDatePrevious(1));
				}*/
			}
		}
		initData(isShowPaihan);
	}
	
	String JPush_Data;
	private void initIntent(){
		Intent intent = getIntent();
		JPush_Data = intent.getStringExtra("JPush_Data");
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		JPushInterface.onResume(this);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		JPushInterface.onPause(this);
	}
	
	private void initData(final boolean flag){

		new Thread() {
			@Override
			public void run() {
				if (HttpRequestHelper.getUserId(SplashActivity.this)) {
					getUserInfo();   //获取用户信息 
					getDownLoadedList();  //下载
					getBannerCache();   // 滚动图缓存
					getGuessBookList();   //猜你喜欢缓存
					getBreakPointCache();  //获取断点列表
					newList = Cache.getNewOrTopBookListCache(2);
					topList = Cache.getNewOrTopBookListCache(3);
//					HttpRequestHelper.synchronousListenStatus(SplashActivity.this, handler); //同步收听记录到服务器
					
				    if (flag) {
						getPaihangData();
						getUserReadInfo();
						getMyReadBookData();
					} else {
						isConnectOver = true;
						try {
							Thread.sleep(1000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
					handler.sendEmptyMessage(4);
				} else {
					handler.sendEmptyMessage(SPLASH_GET_USERID_FAIL);
				}
			}
		}.start();
	}
	
	private void getBreakPointCache(){
		try {
			List<BreakPointTable> m_list = StaticReference.mutilDBSupport.getDao(BreakPointTable.class).queryForAll();
			if (m_list != null && m_list.size() > 0) {
				for (BreakPointTable breakPointTable : m_list) {
					String content = breakPointTable.getContent();
					TemporaryVariable.breakPiontMap.putAll((Map<? extends Integer, ? extends BreakPointBean>) new Gson().fromJson(content,  new TypeToken<LinkedHashMap<Integer, BreakPointBean>>() {}.getType()));
				}
				int c_booKId = (int) SharedPreferencesUtils.getParam(SplashActivity.this,HttpRequestHelper.CONTINUE_PLAY_BOOKID, 0);
				if (c_booKId != 0) {
					BreakPointBean breakPointBean = TemporaryVariable.breakPiontMap.get(c_booKId);
					if (breakPointBean != null) {
						int seekTo = (int) SharedPreferencesUtils.getParam(SplashActivity.this, HttpRequestHelper.CONTINUE_PLAY_BOOK_TIME, 0);
						int c_chapterId = (int) SharedPreferencesUtils.getParam(SplashActivity.this,HttpRequestHelper.CONTINUE_PLAY_CHAPTERID,0);
						breakPointBean.setChapterId(c_chapterId);
						breakPointBean.setSeekTo(seekTo);
						TemporaryVariable.breakPiontMap.put(c_booKId, breakPointBean);
					}
				}
			} else {
				int c_booKId = (int) SharedPreferencesUtils.getParam(SplashActivity.this,HttpRequestHelper.CONTINUE_PLAY_BOOKID, 0);
				if (c_booKId != 0) {
					BreakPointBean breakPointBean = TemporaryVariable.breakPiontMap.get(c_booKId);
					if (breakPointBean != null) {
						int seekTo = (int) SharedPreferencesUtils.getParam(SplashActivity.this, HttpRequestHelper.CONTINUE_PLAY_BOOK_TIME, 0);
						int c_chapterId = (int) SharedPreferencesUtils.getParam(SplashActivity.this,HttpRequestHelper.CONTINUE_PLAY_CHAPTERID,0);
						breakPointBean.setChapterId(c_chapterId);
						breakPointBean.setSeekTo(seekTo);
						TemporaryVariable.breakPiontMap.put(c_booKId, breakPointBean);
					}else {
						breakPointBean = new BreakPointBean();
						breakPointBean.setBookId(c_booKId);
						int seekTo = (int) SharedPreferencesUtils.getParam(SplashActivity.this, HttpRequestHelper.CONTINUE_PLAY_BOOK_TIME, 0);
						int c_chapterId = (int) SharedPreferencesUtils.getParam(SplashActivity.this,HttpRequestHelper.CONTINUE_PLAY_CHAPTERID,0);
						breakPointBean.setChapterId(c_chapterId);
						breakPointBean.setSeekTo(seekTo);
						TemporaryVariable.breakPiontMap.put(c_booKId, breakPointBean);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void getUserInfo(){
		int userId = (int)SharedPreferencesUtils.getParam(this, HttpRequestHelper.USERID, 0);
		UserInfoBean _userInfobean = Cache.getUserInfo(userId);
		if (_userInfobean == null) {
			_userInfobean = new UserInfoBean();
			_userInfobean.setUserId(userId);
		} else{
			UserInfoTable info = Cache.getUserInfoByJson(userId);
			if (info != null && !TextUtils.isEmpty(info.getContent())) {
				UserBaseInfo baseInfo = new Gson().fromJson(info.getContent(), new TypeToken<UserBaseInfo>(){}.getType());
				if (baseInfo != null) {
					_userInfobean.setIsBindTel(baseInfo.getIsBindTel());
					_userInfobean.setIsBindWeixin(baseInfo.getIsBindWeixin());
					_userInfobean.setIsBindQq(baseInfo.getIsBindQq());
					_userInfobean.setCompanyName(baseInfo.getCompanyName());
					_userInfobean.setUserGrade(baseInfo.getUserGrade());
					_userInfobean.setMsgUnread(baseInfo.getMsgUnread());
					_userInfobean.setNotifyUnread(baseInfo.getNofityUnread());
					_userInfobean.setRemindUnread(baseInfo.getRemindUnread());
					_userInfobean.setLoginName(baseInfo.getLoginName());
					_userInfobean.setFaceUrl(baseInfo.getFaceUrl());
					_userInfobean.setConfig(baseInfo.getConfig());
					_userInfobean.setVipInfo(baseInfo.getVipInfo());
				}
			}
		}
		MyUserInfo.getInstance().setUserInfoBean(_userInfobean);
	}
	
	/**
	 * 获取本地缓存的banner
	 */
	private void getBannerCache(){
		try {
			 bannerList = (ArrayList<BannerItem>) StaticReference.mutilDBSupport.getDao(BannerItem.class).queryForAll();
			 if (bannerList != null) {
				 for (int i = 0; i < bannerList.size(); i++) {
					switch (bannerList.get(i).getType()) {
					case 1:
						BookBean bookBean = StaticReference.mutilDBSupport.getDao(BookBean.class).queryBuilder().where().eq("bookId", bannerList.get(i).getId()).queryForFirst();
						if (bookBean != null) {
							List<SelectionVo> vo = StaticReference.mutilDBSupport.getDao(SelectionVo.class).queryBuilder().where().eq("bookId", bookBean.getBookId()).query();
							bookBean.setSectionList(vo);
							bannerList.get(i).setBookModel(bookBean);
						}
						break;
					case 2:
						VideoBean videoBean = StaticReference.mutilDBSupport.getDao(VideoBean.class).queryBuilder().where().eq("id", bannerList.get(i).getId()).queryForFirst();
						if (videoBean != null) {
							bannerList.get(i).setHofModel(videoBean);
						}
						break;
					case 3:
						Banner_H5 banner_H5 = StaticReference.mutilDBSupport.getDao(Banner_H5.class).queryBuilder().where().eq("id", bannerList.get(i).getId()).queryForFirst();
						if (banner_H5 != null) {
							bannerList.get(i).setH5Model(banner_H5);
						}
						break;
					case 4:
						BookListModel bookListModel = StaticReference.mutilDBSupport.getDao(BookListModel.class).queryBuilder().where().eq("listId", bannerList.get(i).getId()).queryForFirst();
						if (bookListModel != null) {
							bannerList.get(i).setBookListModel(bookListModel);
						}
						break;
					}
				}
			 }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void getGuessBookList(){
		try {
			GenericRawResults<BookBean> result = StaticReference.mutilDBSupport.getDao(BookBean.class)
					.queryRaw("select a.about,a.author,a.slogan,a.bookName,a.commentNum,a.createTime,a.nationImg, a.faceImg, a.faceimgplay,a.favorNum,a.goldword,a.listenNum,a.isfavor,a.ensize,a.prosize,a.doubisize,a.bookid,a.isRead,a.isNew,a.canRead,a.free,a.priceTag,a.needBuy from book a inner join  cachetype b on a.bookId = b.bookId and b.type = 0 order by b.tId ",
							new RawRowMapper<BookBean>(){
								@Override
								public BookBean mapRow(String[] columnNames, String[] resultColumns) throws SQLException {
									BookBean bookBean = new BookBean();
									bookBean.setAbout(resultColumns[0]);
									bookBean.setAuthor(resultColumns[1]);
									bookBean.setSlogan(resultColumns[2]);
									bookBean.setBookName(resultColumns[3]);
									bookBean.setCommentNum(resultColumns[4]);
									bookBean.setCreateTime(new Date());
									bookBean.setNationImg(resultColumns[6]);
									bookBean.setFaceImg(resultColumns[7]);
									bookBean.setFaceImgPlay(resultColumns[8]);
									bookBean.setFavorNum(resultColumns[9]);
									bookBean.setGoldWord(resultColumns[10]);
									bookBean.setListenNum(resultColumns[11]);
									bookBean.setIsFavor(Integer.parseInt(resultColumns[12]));
									bookBean.setEnSize(Integer.parseInt(resultColumns[13]));
									bookBean.setProSize(Integer.parseInt(resultColumns[14]));
									bookBean.setDoubiSize(Integer.parseInt(resultColumns[15]));
									bookBean.setBookId(Integer.parseInt(resultColumns[16]));
									bookBean.setIsRead(parseInt(resultColumns[17], 1));
									bookBean.setIsNew(parseInt(resultColumns[18], 1));
									bookBean.setCanRead(parseInt(resultColumns[19], 2));
									bookBean.setFree(parseInt(resultColumns[20], 1));
									bookBean.setPriceTag(resultColumns[21]);
									bookBean.setNeedBuy(parseInt(resultColumns[22], 1));
									return bookBean;
								}});
			
			bookList = (ArrayList<BookBean>) result.getResults();
			for (int i = 0; i < bookList.size(); i++) {
				List<SelectionVo> selectionList = StaticReference.mutilDBSupport.getDao(SelectionVo.class).queryBuilder().where().eq("bookId", bookList.get(i).getBookId()).query();
				if (selectionList != null) {
					bookList.get(i).setSectionList(selectionList);
				}
			}
			
			boolean contains = false;
			int c_bookId = (int) SharedPreferencesUtils.getParam(SplashActivity.this, HttpRequestHelper.CONTINUE_PLAY_BOOKID, 0);
			int c_size = bookList.size();
			for (int i = 0; i < c_size; i++) {
				if (bookList.get(i).getBookId() == c_bookId) {
					contains = true;
					BookBean m_book = bookList.remove(i);
					bookList.add(0, m_book);
					break;
				}
			}
			if (!contains) {
				BookBean c_bean = Cache.getPlayCacheContinueBook(c_bookId);
				if (c_bean != null) {
					bookList.add(0, c_bean);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int parseInt(String temp, int def){
		int x = def;
		try {
			x = Integer.parseInt(temp);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return x;
	}
	
	
	public void getDownLoadedList(){
		try {
			List<CacheTypeBean> cacheTypeBeans = StaticReference.mutilDBSupport.getDao(CacheTypeBean.class).queryBuilder().where().eq("type", 1).query();
			if (cacheTypeBeans != null && cacheTypeBeans.size() > 0) {
				for (CacheTypeBean cacheTypeBean : cacheTypeBeans) {
					if (checkFileExist(cacheTypeBean.getBookId()+"")) {
						if (!TemporaryVariable.downLoadedList.contains(cacheTypeBean.getBookId())) {
							TemporaryVariable.downLoadedList.add(cacheTypeBean.getBookId());
						}
					} else {
						StaticReference.mutilDBSupport.getDao(CacheTypeBean.class).deleteById(cacheTypeBean.getId());
					}
				}
			}
			deleteFile(TemporaryVariable.downLoadedList);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @param list
	 */
	private void deleteFile(ArrayList<Integer> list){
		try {
			File file = new File(FileUtil.getFileCachePath() + DownLoadInfo.DOWNLOAD);
			if (file.exists()) {
				File[] files = file.listFiles();
				for (int i = 0; i < files.length; i++) {
					if (!list.contains(Integer.parseInt(files[i].getName()+""))) {
						delete(files[i]);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @param file
	 */
	private void delete(File file) {
		if (file.isFile()) {
			file.delete();
			return;
		}
		if (file.isDirectory()) {
			File[] childFiles = file.listFiles();
			if (childFiles == null || childFiles.length == 0) {
				file.delete();
				return;
			}
			for (int i = 0; i < childFiles.length; i++) {
				delete(childFiles[i]);
			}
			file.delete();
		}
	} 
	
	/**
	 * 检查下载的文件是否存在
	 * @param bookId
	 */
	public boolean checkFileExist(String fileName){
		try {
			File downFile = new File(FileUtil.getFileCachePath() + DownLoadInfo.DOWNLOAD + "/" + fileName);
			if (downFile.exists()) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	boolean isConnectOver = false;
	
	/**
	 * 加锁双向判断调转时机
	 */
	synchronized private void checkOver() {
		if(isConnectOver) {
			jumpTo();
		}
	}
	
	private void jumpTo(){
		Intent intent = null;
		if ((boolean)SharedPreferencesUtils.getParam(this, "isFirst", true)) {
			intent = new Intent(this,WelcomeActivity.class);
		}else {
			intent = new Intent(this, MainActivity.class);
			if (!TextUtils.isEmpty(JPush_Data)) {
				intent.putExtra("JPush_Data", JPush_Data);
			}
			HttpRequestHelper.bannerItemList.addAll(bannerList);
			HttpRequestHelper.bookList.addAll(bookList);
			HttpRequestHelper.newList.addAll(newList);
			HttpRequestHelper.topList.addAll(topList);
//			HttpRequestHelper.bookListMap.put(0, bookList == null ? new ArrayList<BookBean>() : bookList); //猜你喜欢
//			HttpRequestHelper.bookListMap.put(2, newList == null ? new ArrayList<BookBean>() : newList); //最新
//			HttpRequestHelper.bookListMap.put(3, topList == null ? new ArrayList<BookBean>() : topList); //周top10
		}
		startActivity(intent);
		finish();
	}
	
	private void initView(){
		image_phb_top = (ImageView) findViewById(R.id.image_phb_top);
		imageView1 = (ImageView) findViewById(R.id.imageview1);
		imageView1.setImageBitmap(CommonMethod.readBitMap(this, R.drawable.dengjibackground));
		image_phb_top.setImageBitmap(CommonMethod.readBitMap(this, R.drawable.mydsb));
		tv_username = (TextView) findViewById(R.id.tv_username);
		tv_grade = (TextView) findViewById(R.id.tv_grade);
		tv_has_read = (TextView) findViewById(R.id.tv_has_read);
		tv_jinji = (TextView) findViewById(R.id.tv_jinji);
		image_up = (ImageView) findViewById(R.id.image_up);
		image_face = (RoundImageView) findViewById(R.id.image_face);
		image_face.setType(RoundImageView.TYPE_ROUND);
		
		image_backgroup = (ImageView) findViewById(R.id.image_backgroup);
		image_backgroup.setImageBitmap(CommonMethod.readBitMap(this, R.drawable.phbbg));
		
		scrollView2 = (PullToRefreshScrollView) findViewById(R.id.scrollview2);
		scrollView2.setMode(Mode.DISABLED);
		tv_china = (TextView) findViewById(R.id.tv_china);
		tv_other = (TextView) findViewById(R.id.tv_other);
		tv_usa = (TextView) findViewById(R.id.tv_usa);
		tv_eur = (TextView) findViewById(R.id.tv_eur);
		
		listview_paim = (ListView) findViewById(R.id.listview_paim);
		adapter = new PaihangAdapter(this, pList);
		listview_paim.setAdapter(adapter);
		
		
		gv_booklist = (GridView) findViewById(R.id.gv_booklist);
		lichengBooklistAdapter = new LichengBooklistAdapter(this,list);
		gv_booklist.setAdapter(lichengBooklistAdapter);
		gv_booklist.setSelector(new ColorDrawable(Color.TRANSPARENT));
		
		image_share = (ImageView) findViewById(R.id.image_share);
		image_to_read = (ImageView) findViewById(R.id.image_to_read);
		
		image_to_read.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				jumpTo();
			}
		});
		
		image_share.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				int userId = (int) SharedPreferencesUtils.getParam(SplashActivity.this, HttpRequestHelper.USERID, 0);
				if (userId == 0) {
					return;
				}
				String url = HttpCommonInfo.MURL +"user-share?userId=" + userId;
				String userName = MyUserInfo.getInstance().getUserInfoBean().getLoginName();
				String title = String.format(getResources().getString(R.string.text_share_splash_title), TextUtils.isEmpty(userName) ? "" : userName + "的");
				new ShareView(SplashActivity.this, SplashActivity.this).setTitle(title).setUrl(url).setContent(getResources().getString(R.string.text_share_splash_content)).setType(1).show(findViewById(R.id.relative_main));
			}
		});
		
	}
	
	
	
	/**
	 * 书单
	 */
	private void getMyReadBookData(){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, ""+SharedPreferencesUtils.getParam(this, HttpRequestHelper.USERID, 0)));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_INDEX, 0+""));
		params.add(new BasicNameValuePair("pageSize", String.valueOf(9)));
		HttpRequestHelper.executeHttpDataUnThread(this, HttpRequestHelper.MY_READ_BOOK, params, handle, GETMYREADBOOK_SUCCESS,-56);
	}
	
	/**
	 * 排行版
	 */
	private void getPaihangData(){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, ""+SharedPreferencesUtils.getParam(this, HttpRequestHelper.USERID, 0)));
		HttpRequestHelper.executeHttpDataUnThread(this, HttpRequestHelper.USER_RANK_LIST, params, handle, HttpRequestHelper.GETDATA_SUCCESS,-56);
	}
	
	/**
	 * 用户读书信息
	 */
	private void getUserReadInfo(){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(this, HttpRequestHelper.USERID, 0))));
		HttpRequestHelper.executeHttpDataUnThread(this, HttpRequestHelper.USER_READ_INFO, params, handle, GETUSERINFO_SUCCESS,-56);
	}
	
	private void showData(ReadLichengBean lichengBean){
		tv_china.setText(lichengBean.getCnBookNum()+"本");
		tv_usa.setText(lichengBean.getUsaBookNum()+"本");
		tv_eur.setText(lichengBean.getEurBookNum()+"本");
		tv_other.setText(lichengBean.getOtherBookNum()+"本");
		
		ImageLoader.getInstance().displayImage(lichengBean.getFaceUrl(), image_face, options);
		tv_username.setText(lichengBean.getUserName()+"");
		tv_grade.setText(lichengBean.getUserGrade()+"");
		tv_has_read.setText(String.format("已读%s本", lichengBean.getBookNum()+""));
		if (lichengBean.getNeedNum() == 0) {
			tv_jinji.setText(String.format("已最高等级"));
			image_up.setVisibility(View.GONE);
		}else {
			tv_jinji.setText(String.format("+%s晋级", lichengBean.getNeedNum()+""));
			image_up.setVisibility(View.VISIBLE);
		}
	}
	
	DisplayImageOptions options;
	private void initImageLoader(){
		options = new DisplayImageOptions.Builder()
		.showImageOnLoading(R.drawable.me_user)
		.showImageForEmptyUri(R.drawable.me_user)
		.showImageOnFail(R.drawable.me_user).cacheInMemory(true)
		.cacheOnDisk(true).considerExifParams(true)
		.bitmapConfig(Bitmap.Config.RGB_565).build();
	}

	@Override
	public boolean handleMessage(Message msg) {
		ShareOpUtils.handleShareCallBack(SplashActivity.this, msg);
		return false;
	}
}
